﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace ECS.Framework
{
    public class FormBase : Control
    {
        #region private properties
        /// <summary>
        /// 
        /// </summary>
        private Control overlay = null;
        /// <summary>
        /// 
        /// </summary>
        private Form _mainForm = null;
        #endregion
        

        public Tuple<Panel, Label> createProgressControls(Size size)
        {
            var progreassBar = new ProgressBar()
            {
                Style = ProgressBarStyle.Marquee,
                Size = new System.Drawing.Size(200, 40),
                MarqueeAnimationSpeed = 40
            };
            var m_panel = new Panel();
            m_panel.Size = progreassBar.Size;
            m_panel.Location = new Point((size.Width - m_panel.Width) / 2, (size.Height - m_panel.Height) / 2);
            m_panel.BackColor = Color.FromArgb(0, 0, 0, 0);
            //var m_styles = AppCode.Utils.CommonConfiguration.getstyleSheets();
            var m_lblCaption = new Label()
            {
                Text = "Please wait, now processing...",
                AutoSize = false,
                Size = new Size(200, this.Font.Height * 5 / 4), //m_styles.FormalFont.Height * 5 / 4),
                Location = new Point(m_panel.Location.X, m_panel.Location.Y + m_panel.Size.Height),
                BackColor = Color.SteelBlue,
                ForeColor = Color.White,
                Font = this.Font, //AppCode.Utils.CommonConfiguration.getstyleSheets().FormalFont,
                TextAlign = System.Drawing.ContentAlignment.MiddleCenter
            };
            m_panel.Controls.Add(progreassBar);
            return Tuple.Create(m_panel, m_lblCaption);
        }

        private void showWaitIndicator()
        {
            this.Cursor = Cursors.WaitCursor;
            //this.radPanelReport.Hide();

            var m_waitIndicator = new Panel();

            m_waitIndicator.Dock = DockStyle.Fill;
           
            var m_controls = this.createProgressControls(this.ClientSize); //WaitIndicator.OverlayTarget.createProgressControls(this.ClientSize);
            m_waitIndicator.Controls.Add(m_controls.Item1);
            m_waitIndicator.Controls.Add(m_controls.Item2);
            m_controls.Item1.BringToFront();
            m_controls.Item2.BringToFront();
            //this.SuspendLayout();
            this.Controls.Add(m_waitIndicator);

            // set Anchor to None after everything was done to make the content maintain its center position
            m_controls.Item1.Anchor = AnchorStyles.None;
            m_controls.Item2.Anchor = AnchorStyles.None;

            ////
            this.overlay = m_waitIndicator;
            //this.noDataShown = false;

            this.overlay.BringToFront();
            //this.ResumeLayout();
        }

        private void removeOverlay()
        {
            if (this.overlay != null) this.Controls.Remove(this.overlay);
        }
        
        private void FinishLoad(object state)
        {
            //this.Cursor = Cursors.Default;
            //removeOverlay();

            this.Invoke(new Action(() =>
            {
                this.Cursor = Cursors.Default;
                this.removeOverlay();
            }));
        }
    }
}
